/*
    The MIT License

    Copyright (c) 2010 IFMO/GameDev Studio

    Permission is hereby granted, free of charge, to any person obtaining a copy
    of this software and associated documentation files (the "Software"), to deal
    in the Software without restriction, including without limitation the rights
    to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
    copies of the Software, and to permit persons to whom the Software is
    furnished to do so, subject to the following conditions:

    The above copyright notice and this permission notice shall be included in
    all copies or substantial portions of the Software.

    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
    THE SOFTWARE.
*/

#pragma once

/*-----------------------------------------------------------------------------
	Physics 
-----------------------------------------------------------------------------*/

class EPhysics : public IPhysics {
	public:
									EPhysics		( void );
									~EPhysics		( void );
								
		virtual void				RunSimulation	( uint dtime );
		virtual void				DebugRender		( IPxDVScene dbg_scene );
		
		virtual void				SetGravity		( const EVector &gravity );
		virtual EVector				GetGravity		( void ) const;
													
		virtual IPxPhysEntity		AddEntity		( void );
		virtual IHrPhysCharacter	AddCharacter	( float heigth, float radius, float climbing_slope, float stair_step );
		virtual IPxPhys6DOF			Add6DOF			( IPxPhysEntity a, IPxPhysEntity b, EMatrix &basis_a, const EMatrix &basis_b );
		virtual IPxPhys6DOF			Add6DOF			( IPxPhysEntity b, const EMatrix &basis_b );
		
		btDynamicsWorld			*	World			( void ) { return dynamicsWorld; }
		
	protected:
		EDebugDraw				debug_drawer;
		void					InitDebugRender			( void );
		void					ShutdownDebugRender		( void );
		void					ConfigureDebugRender	( void );

	public:		
		IPxVar	phys_debug					;
		IPxVar	phys_draw_wireframe			;
		IPxVar	phys_draw_aabb				;
		IPxVar	phys_draw_features_text		;
		IPxVar	phys_draw_contact_points	;
		IPxVar	phys_no_deactivation		;
		IPxVar	phys_no_help_text 			;
		IPxVar	phys_draw_text				;
		IPxVar	phys_profile_timings 		;
		IPxVar	phys_enable_sat_comparison 	;
		IPxVar	phys_disable_bullet_lcp		;		
		IPxVar	phys_enable_ccd 			;
		IPxVar	phys_draw_constraints 		;
		IPxVar	phys_draw_constraint_limits ;
		IPxVar	phys_fast_wireframe 		;
		
		IPxVar	phys_max_substeps			;
		IPxVar	phys_fixed_timestep			;
		IPxVar	phys_linear_damping			;
		IPxVar	phys_angular_damping		;
		IPxVar	phys_linear_sleep_treshold	;
		IPxVar	phys_angular_sleep_treshold	;
		IPxVar	phys_contact_proc_treshold	;

	protected:		
		btBroadphaseInterface				*broadphase;
		btDefaultCollisionConfiguration		*collisionConfiguration;
		btCollisionDispatcher				*dispatcher;
		btSequentialImpulseConstraintSolver	*solver;
		btDiscreteDynamicsWorld				*dynamicsWorld;
		
	};